
function lodingtable(){
	var testInfo = $('#selectForm').serializeObject();
	var selectJsonStr=JSON.stringify(testInfo);//将表单中的数据转成json
	$('#testTable').DataTable({
		"processing": true,	//处理状态
        "serverSide": true,	//开启服务器模式     默认不开启的
        "stateSave":false,	//开启浏览器本地缓存
        //"stateDuration":0,	//开启localStorage
        "autoWidth":true,	//自动适应宽高
        "ordering": true,	//开启排序
        "paging": true,		//开启自动分页
//        "pagingType":"full_numbers",	//分页类型
        "iDisplayLength":10,		//每页展示的条数   默认展示10条
        "bLengthChange":true,		//可以改变分页数
        "info": true,					//显示表格信息
        "bDestroy": true,				//如已存在相同dataTable对象，则销毁重建
        "searching": false,	//关闭搜索
        "aLengthMenu":[[10,20,30],[10,20,30]],
	     "sDom":'<"info-toolbar">rtilp',	//和1.9版本的dom相同
	     "columns" : [
	         { "data" : "projectName"},
	         { "data" : "projectManager","sDefaultContent" : "XX"},
	         { "data" : "projectType"},
	         { "data" : "projectImgUrl"}
	     ],
	     "createdRow": function ( row, data, index ) {
	    	// console.log("第"+index+"行的信息");
	    	// console.log(data);
	    	 $(row).children('td').attr('style', 'text-align: center;');
        	 if(index % 2 == 1){
        		$(row).css("background","#F4F4F4");
        	 }
	     },
	     "columnDefs": [
	                    {
	    				    "targets": [3],
	    				    "data":"projectImgUrl",
	    				    "render": function(data, type, full) {
	    				    var co =data.lastIndexOf("\\");
	    				    var newUrl = "/file/"+data.substring(co+1);
	    				    	return "<img src=\""+newUrl+"\" width='100px'>";
	    				      }
	    				  }  , 
				{
					    "targets": [4],
					    "data":"project_id",
					    "render": function(data, type, full) {
					    	return "<a href='#' onclick='updateProject(\""+data+"\")'> 编辑</a>| "+ "<a href='#' onclick='deleteProject(\""+data+"\")'> 删除</a> ";
					      }
					  }
                	

             ],
             "ajax": {
            	 "type":"post",
                 "url": getRootPath()+"/test/queryProjectList.action",
                 "dataType":"json",
                 "data":{signupForm:selectJsonStr}
             },
             "language": {   //定义统一的提示语言
            	 "decimal":",",
            	 "thousands":".",
            	 "lengthMenu": "每页显示 _MENU_ 条记录",
                 "zeroRecords": "暂无数据",
                 "info": " _PAGE_ / _PAGES_",
                 "infoEmpty": "没有数据",
                 "infoFiltered": "(filtered from _MAX_ total records)",
                 "emptyTable":     "没有数据",
                 "info":           "当前显示第 _START_ 到第 _END_ 条,共 _TOTAL_ 条记录",
                 "infoEmpty":      "显示第 0 到第 0 条（总 0 条）",
                 "infoFiltered":   "(来自 _MAX_ 条的过滤数据)",
                 "infoPostFix":    "",
                 "thousands":      ",",
                 "loadingRecords": "载入中...",
                 "processing":     "正在处理中...",
                 "search":         "搜索：",
                 "zeroRecords":    "无相关数据",
                 "paginate": {
                     "first":      "首页",
                     "last":       "尾页",
                     "next":       "下一页",
                     "previous":   "上一页"
                 }, 
                 "aria": {
                     "sortAscending":  ": 升序排列",
                     "sortDescending": ": 降序排列"
                 }
             
             }
	    });
	 
}
$(function(){
	jQuery_dataTable_extend_FirstAndEnd();
	lodingtable();
});


function queryTestMessage(){
	 lodingtable();
}

layui.use(['form','element','layer'], function(){
	  
	  $("#addTest").click(function(){
		  parent.layer.open({
			  title:"添加项目",
			  type: 2,
			  id:123,
			  area: ['400px', '550px'],
			  content: getRootPath()+'/test/addTestProject.jsp' //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		  });
	});
})	

function updateProject(project_id){
	layui.use('layer', function(){
		  var layer = layui.layer;
		  parent.layer.open({
			  title:"修改项目信息",
			  type: 2,
			  area: ['400px', '235px'],
			  content: getRootPath()+'/test/addTestProject.jsp?project_id='+project_id ,
			  data:{"project_id":project_id}
		  });
	});
}
/**
 * 删除访谈信息
 */
function deleteProject(project_id){

	parent.layer.confirm('确定要删除这条信息吗？', {
		  btn: ['是', '否'] //可以无限个按钮
		}, function(index, layero){
		  //按钮【按钮一】的回调
			$.ajax({
		        url : getRootPath()+"/test/deleteTestProject.action",
		        type : "post",
		        data : {
		        	project_id : project_id
		        },
		        datatype : "text",
		        success : function (data) {
		        	if(data=='success'){
		        		parent.layer.msg('删除成功', {
						    icon: 1,
							time: 500 //（如果不配置，默认是3秒）
						}, function(){
							var data_pjax=$("#admui-siteConTabs ul>li.active>span",window.parent.document).attr("data-pjax");
							parent.document.getElementById(data_pjax).contentWindow.lodingtable();
							parent.layer.closeAll();
							
						});
		        	}
		        }
		    })
		}, function(index){
		  //按钮【按钮二】的回调
			layer.closeAll('dialog');
		});
}
